package com.hua.api.core.activemq.consumer;


import com.alibaba.fastjson.JSONObject;
import com.hua.api.core.activemq.consumer.event.ActiveMqEvent;
import com.hua.api.core.activemq.consumer.event.MqEventFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class QueueConsumer {


    @Autowired
    private MqEventFactory mqEventFactory;

    /**
     * {
     *     target: 'mall',
     *     event: 'order_created',
     *     data: {
     *          order_no: ''
     *     }
     * }
     * */
    public void queuePortal(String message){

        log.info("QueueConsumer.queuePortal(message={})",message);
        JSONObject msg = JSONObject.parseObject(message);
        String event = msg.getString("event");
        ActiveMqEvent activeMqEvent = mqEventFactory.getMqEventFactory(event);
        if(null!=activeMqEvent){
            activeMqEvent.doEvent(msg.getJSONObject("data"));
        }else{
            log.warn("不能获取event事件 event={}",event);
        }

    }


}
